﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using mscook.core.domain;
using NHibernate.Linq;

namespace mscook.core.repositories
{
    public class ResourceOfTypeRepository : Repository<ResourceOfType>, mscook.core.repositories.IResourceOfTypeRepository
    {
        public IList<ResourceType> GetByResourceId(string resourceId)
        {

            var query = (from x in this.Session.Query<ResourceOfType>()
                         where x.IsDelete == false
                         && x.ResourceId == resourceId
                         select x.ResourceType)
            .Where(o => o.IsDelete == false).Distinct();
            return query.ToList();


        }

        public ResourceOfType GetByResourceAndType(string resourceId, string typeId)
        {
            var query = (from x in this.Session.Query<ResourceOfType>()
                         where x.IsDelete == false
                         && x.ResourceId == resourceId
                         && x.ResourceType.Id == typeId
                         select x)
         .Where(o => o.IsDelete == false);
            return query.SingleOrDefault();
        }
    }
}
